#include "log.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>

#if   defined(_MSC_VER) && (_MSC_VER>1000)
#pragma warning(disable:996 267)
#endif

#define STDIO_ASSERT() { assert(g_filetype | RAYLOG_TYPE_STD); \
                         assert(g_log);};

extern unsigned    g_filetype;
extern FILE*       g_log;
extern unsigned    g_itemcolor;
extern unsigned    g_enabled;

static unsigned g_screen_width = 80;

static void printBanner(char* str)
{
    int len = strlen(str);
    int limit = (g_screen_width - len) / 2;
    int i;
    for (i=0; i<limit; i++)
        printf("=");
    printf(str);
    for (i=0; i<limit; i++)
        printf("=");
    printf("\n");
}

static void printCenter(char* str)
{
    int len = strlen(str);
    int limit = (g_screen_width - 1 - len) / 2;
    int i;
    for (i=0; i<limit; i++)
        printf(" ");
    printf(str);

    for (i=0; i<limit; i++)
        printf(" ");
    printf("\n");
}

void _writeSTD(char* content, unsigned type)
{
    STDIO_ASSERT();
    assert( type < RAYLOG_FORMAT_COUNT );
    CHECK_ENABLE();
    switch(type)
    {
    case RAYLOG_TITLE:
        return;
    case RAYLOG_HEADER:
        printCenter(content);
        return;
    case RAYLOG_SUBHEADER:
        printBanner(content);
        return;
    case RAYLOG_LIST:
        printf(">> %s", content);
        return;
    case RAYLOG_CONTENT:
        printf(content);
        return;
    }
}

void _cwriteSTD(char* content, unsigned type, unsigned cltype)
{
    _writeSTD(content, type);
    (cltype);   // ignore color
}

